const arr = [10, 9, 8, 7, 6, 5, 5, 4, 3]

function incorporate(arr) {
    if (arr.length <= 1) return arr
    const middle = Math.floor(arr.length / 2)
    const left = incorporate(arr.slice(0, middle))
    const right = incorporate(arr.slice(middle))
    return merge(left, right)
}

function merge(left, right) {
    const result = []
    let i = 0
    let j = 0
    while (i < left.length && j < right.length) {
        if (left[i] < right[j]) {
            result.push(left[i])
            i++
        } else {
            result.push(right[j])
            j++
        }
    }
    return result.concat(i < left.length ? left.slice(i) : right.slice(j))
}

console.log(incorporate(arr))